﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;

namespace Prototipo.CMS.Models
{
    public class Configuration
    {
        private string _pathSite;
        private XDocument xDoc;

        public Configuration()
        {
            Theme = new Theme();
        }

        public Configuration(string pathSite) : this()
        {
            _pathSite = pathSite;
            xDoc = XDocument.Load(string.Format("{0}/Prototipo.CMS.config", pathSite));

            Theme.Name = xDoc.Root.Element("Configuration").Element("Theme").Value;
            Theme.Path = string.Format("~/Themes/{0}/", Theme.Name);
            Theme.Layout = string.Format("{0}/Layout.cshtml", Theme.Path);

        }

        public Theme Theme { get; set; }

        public void Save()
        {
            xDoc.Root.Element("Configuration").Element("Theme").Value = Theme.Name;

            xDoc.Save(string.Format("{0}/Prototipo.CMS.config", _pathSite));
        }
    }

    public class Theme
    {
        public string Name { get; set; }
        public string Path { get; set; }
        public string Layout { get; set; }
    }

}


